<?php

/**
 * Created by PhpStorm.
 * User: liuxiu
 * Date: 2021/12/16
 * Time: 16:03
 */

namespace business\procurement\repositories;


use yii\db\Query;

class BiddingAnnouncementRepository
{

    public function getBiddingCount($condition = [])
    {
        $query = (new Query())
            ->select('count(uid) as total')
            ->from('b2b_data_center.uuc_bidding_announcement');
        if (!empty($condition)) {
            $query = $query->andWhere($condition);
        }
        return $query->createCommand(\Yii::$app->db)->queryScalar();
    }

    public function getBidding($condition = [], $field = '*', $page = 1, $pagesize = 50)
    {
        $query = (new Query())
            ->from('b2b_data_center.uuc_bidding_announcement')
            ->select($field);
        if (!empty($condition)) {
            $query = $query->andWhere($condition);
        }
        $query->offset(intval($page - 1) * $pagesize)->limit($pagesize);
        return $query->orderBy(['uid' => SORT_ASC])
            ->createCommand(\Yii::$app->db)
            ->queryAll();
    }
}